package restaurant.iterators;

import static org.junit.Assert.*;

import java.util.NoSuchElementException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import restaurant.CustomerComments;
import restaurant.Rating;

/**
 * Test case for the RatingsIterator class. Tests to ensure the {@code hasNext}
 * and {@code next} methods work correctly.
 * 
 * @author Odessa
 */
public class RatingsIteratorTest
{
	CustomerComments comments;
	Iterator it;



	/**
	 * Sets up the test fixture.
	 * 
	 * @throws Exception the exception
	 */
	@Before
	public void setUp() throws Exception
	{
		comments = new CustomerComments();
		comments.addRating(1, 4, "Great");
	}



	/**
	 * Tears down the test fixture.
	 * 
	 * @throws Exception the exception
	 */
	@After
	public void tearDown() throws Exception
	{
		comments = null;
		it = null;
	}



	/**
	 * Test method for {@link restaurant.iterators.RatingsIterator#hasNext()}. Tests
	 * hasNext() if there is another rating for the item.
	 */
	@Test
	public void testHasNext_Yes()
	{
		it = comments.getRatingsIterator(1);
		assertTrue(it.hasNext());
	}



	/**
	 * Test method for {@link restaurant.iterators.RatingsIterator#hasNext()}. Tests
	 * hasNext() if there are no more ratings for the item.
	 */
	@Test
	public void testHasNext_No()
	{
		it = comments.getRatingsIterator(2);
		assertFalse(it.hasNext());
	}



	/**
	 * Test method for {@link restaurant.iterators.RatingsIterator#next()}. Tests next()
	 * when there is another rating for the item.
	 */
	@Test(expected = NoSuchElementException.class)
	public void testNext_MoreRatings()
	{
		it = comments.getRatingsIterator(1);
		Rating r = new Rating(1, 1, 4, "Great");

		assertEquals(r, it.next());
	}



	/**
	 * Test method for {@link restaurant.iterators.RatingsIterator#next()}. Tests next()
	 * if there are no more ratings for the item.
	 */
	@Test(expected = NoSuchElementException.class)
	public void testNext_NoMoreRatings()
	{
		it = comments.getRatingsIterator(2);
		it.next();
	}

}
